import os
from PIL import Image, ImageDraw, ImageFont

def create_icon(name, color, output_path):
    """Create profile page icons."""
    size = 48
    img = Image.new('RGBA', (size, size), (0, 0, 0, 0))
    draw = ImageDraw.Draw(img)
    
    # Convert hex color to RGB
    if color.startswith('#'):
        color = color[1:]
    r = int(color[0:2], 16)
    g = int(color[2:4], 16)
    b = int(color[4:6], 16)
    color_rgb = (r, g, b)
    
    center = size // 2
    
    if name == 'waiting':
        # Clock icon for pending payment
        draw.ellipse((8, 8, size-8, size-8), outline=color_rgb, width=3)
        draw.line([(center, center), (center, 16)], fill=color_rgb, width=2)
        draw.line([(center, center), (center+8, center)], fill=color_rgb, width=2)
        
    elif name == 'success':
        # Check mark for success
        draw.ellipse((4, 4, size-4, size-4), outline=color_rgb, width=3)
        # Check mark
        points = [(14, 24), (20, 30), (34, 16)]
        for i in range(len(points)-1):
            draw.line([points[i], points[i+1]], fill=color_rgb, width=3)
            
    elif name == 'download':
        # Truck icon for shipping
        # Truck body
        draw.rectangle((8, 18, 28, 32), outline=color_rgb, width=2)
        # Truck cab
        draw.rectangle((28, 14, 38, 32), outline=color_rgb, width=2)
        # Wheels
        draw.ellipse((12, 30, 20, 38), outline=color_rgb, width=2)
        draw.ellipse((30, 30, 38, 38), outline=color_rgb, width=2)
        
    elif name == 'info':
        # Location pin for address
        draw.ellipse((12, 8, 36, 32), outline=color_rgb, width=3)
        draw.ellipse((18, 14, 30, 26), fill=color_rgb)
        draw.polygon([(24, 32), (20, 38), (28, 38)], fill=color_rgb)
        
    elif name == 'contact':
        # Phone icon for contact
        draw.rounded_rectangle((14, 8, 34, 40), radius=4, outline=color_rgb, width=3)
        draw.rectangle((16, 12, 32, 16), fill=color_rgb)
        draw.ellipse((22, 32, 26, 36), fill=color_rgb)
        
    elif name == 'about':
        # Info icon for about
        draw.ellipse((8, 8, size-8, size-8), outline=color_rgb, width=3)
        draw.ellipse((22, 16, 26, 20), fill=color_rgb)
        draw.rectangle((22, 24, 26, 34), fill=color_rgb)
        
    elif name == 'logout':
        # Exit icon for logout
        draw.rectangle((8, 16, 28, 32), outline=color_rgb, width=2)
        draw.line([(28, 24), (40, 24)], fill=color_rgb, width=2)
        # Arrow
        draw.polygon([(36, 20), (40, 24), (36, 28)], fill=color_rgb)
        draw.line([(12, 8), (12, 16)], fill=color_rgb, width=2)
        draw.line([(12, 32), (12, 40)], fill=color_rgb, width=2)
    
    img.save(output_path)
    print(f"创建图标: {output_path}")

def main():
    # Create output directory
    output_dir = "../frontend/images/icons"
    os.makedirs(output_dir, exist_ok=True)
    
    # Icon definitions
    icons = [
        ('waiting', 'ff6b9d'),      # Pink for waiting
        ('success', 'ff6b9d'),      # Pink for success  
        ('download', 'ff6b9d'),     # Pink for shipping
        ('info', '666666'),         # Gray for info
        ('contact', '666666'),      # Gray for contact
        ('about', '666666'),        # Gray for about
        ('logout', 'f5222d'),       # Red for logout
    ]
    
    for name, color in icons:
        output_path = os.path.join(output_dir, f"{name}.png")
        create_icon(name, color, output_path)
    
    print("所有图标创建完成！")

if __name__ == "__main__":
    main()